package com.example.black.myapplication.paintlearn;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Typeface;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.example.black.myapplication.R;

/**
 * <pre>
 *     author : 28476
 *     e-mail : hao.wang@1hai.cn
 *     time   : 2018/11/22/9:36
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public class PaintView extends View {
    private Paint paint;
    private Path path;
    public PaintView(Context context) {
        this(context,null);
    }

    public PaintView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public PaintView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        paint = new Paint();
         path = new Path();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint.reset();//重置
        paint.setColor(getResources().getColor(R.color.colorPrimaryBlueDark));//画笔颜色
        paint.setAlpha(50);//透明度
        paint.setStrokeWidth(30);
        paint.setStyle(Paint.Style.STROKE);//填充
//        paint.setStyle(Paint.Style.FILL_AND_STROKE);//填充且描边
//        paint.setStyle(Paint.Style.STROKE);//描边
        //paint.setStrokeCap(Paint.Cap.BUTT);//也类似方形
        //paint.setStrokeCap(Paint.Cap.ROUND);//圆形
        paint.setStrokeCap(Paint.Cap.SQUARE);
        //canvas.drawPaint(paint);//可以构建一个普通画板，由用户自己绘制？
     //   canvas.drawCircle(100,100,50,paint);
        //paint.setStrokeJoin(Paint.Join.MITER);//斜切割的锐角
        paint.setStrokeJoin(Paint.Join.ROUND);//斜切割是圆角
        paint.setAntiAlias(true);//抗锯齿
        paint.setDither(true);//防止抖动
      //  paint.setStrokeJoin(Paint.Join.BEVEL);//直线
//        path.moveTo(300,50);//开始点的位置
//        path.lineTo(300,400);
//        path.lineTo(100,400);
//        canvas.drawPath(path,paint);
       // canvas.drawLine(20,20,150,150,paint);

        //···········文字绘制··········
        paint.getFontSpacing(); //字符行间距
        paint.getLetterSpacing();//字符间距
        paint.setStrikeThruText(true);//删除线
        paint.setTextSize(15);//文字大小
        paint.setTypeface(Typeface.DEFAULT_BOLD);
        paint.setTextSkewX(-0.25f);//斜体
        paint.setTextAlign(Paint.Align.RIGHT);//对齐方式

       //int breakText = paint.breakText() 计算文字的 字符长度，字符个数，显示真实长度
        //paint.getTextBounds();//获取文本宽高

       // paint.measureText(text); 获取文本宽度，
        //paint.getTextWidths()获取每一个文本宽度，返回字符数

        //·····基线的效果······
    }
}
